﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace remes.BLoc.UI
{
   /// <summary>
   /// Interaction logic for SelectTargetLanguagesDialog.xaml
   /// </summary>
   public partial class SelectTargetLanguagesDialog : Window
   {
      public SelectTargetLanguagesDialog()
      {
         Languages = new List<SelectableLanguageTuple>();
         InitializeComponent();
      }

      public void SetAvailableLanguages(IEnumerable<string> languages)
      {
         Languages.Clear();
         foreach (var lang in languages)
         {
            Languages.Add(new SelectableLanguageTuple(lang, true));
         }
      }

      public List<SelectableLanguageTuple> Languages { get; private set; }

      public IEnumerable<string> SelectedLanguages
      {
         get
         {
            foreach (var lang in Languages)
            {
               if (lang.IsSelected)
               {
                  yield return lang.Language;
               }
            }
         }
      }

      private void OkButton_Click(object sender, RoutedEventArgs e)
      {
         if (SelectedLanguages.ToList().Count > 0)
         {
            DialogResult = true;
            Close();
         }
      }
   }

   public class SelectableLanguageTuple
   {
      public SelectableLanguageTuple(string language, bool isSelected)
      {
         Language = language;
         IsSelected = isSelected;
      }

      public string Language { get; private set; }

      public bool IsSelected { get; set; }
   }
}
